<?php
/**
 * Created by PhpStorm
 * User: huangjiacheng
 * Date: 2023/6/7
 * Time: 15:17
 */

namespace app\common\service;


class CurlService
{

    protected function alarm($webhook,$title,$msg){

        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $webhook);
        curl_setopt($curl,CURLOPT_SSL_VERIFYPEER,false);
        curl_setopt($curl,CURLOPT_SSL_VERIFYHOST,false);
        curl_setopt($curl, CURLOPT_POST, 1);
        curl_setopt($curl, CURLOPT_HTTPHEADER,array('Content-Type: application/json;charset=utf-8'));
        $post_data = [
            'msgtype' => 'text',
            'text' => [
                'content' => $title."\n".$msg,
            ]
        ];
        $post_data = json_encode($post_data);
        curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
        $data = curl_exec($curl);
        curl_close($curl);
    }
}